#include"PlayerController.h"

#include"Player.h"

PlayerController::PlayerController(QWidget *parent, Player *player):QWidget(parent){
	m_player = player;
	
	m_layout = new QHBoxLayout(this);
	setLayout(m_layout);
	
	m_buttonPrev = new QPushButton(/*QIcon::fromTheme("media-skip-backward"), "Prev", */this);
	m_layout->addWidget(m_buttonPrev);
	
	m_buttonPlayPause = new QPushButton(/*QIcon::fromTheme("media-playback-start"), "Play", */this);
	m_layout->addWidget(m_buttonPlayPause);
	
	m_buttonStop = new QPushButton(/*QIcon::fromTheme("media-playback-stop"), "Stop", */this);
	m_layout->addWidget(m_buttonStop);
	m_buttonStop->setEnabled(false);
	
	m_buttonNext = new QPushButton(/*QIcon::fromTheme("media-skip-forward"), "Next", */this);
	m_layout->addWidget(m_buttonNext);
	
	//m_slider = new Phonon::SeekSlider(this);
	//m_slider->setMediaObject(m_player->mediaObject());
	//m_layout->addWidget(m_slider);

	//m_volumeDock = new QDockWidget(0);
	//m_volumeDock->setFeatures(QDockWidget::NoDockWidgetFeatures);
	//m_volumeSlider = new Phonon::VolumeSlider(m_volumeDock);
	//m_volumeSlider->setAudioOutput(m_player->audioOutput());
	//m_volumeSlider->setOrientation(Qt::Vertical);
	//m_volumeDock->setWidget(m_volumeSlider);
	//m_volumeDock->hide();
	
	m_volumeButton = new QPushButton(QIcon::fromTheme("player-volume"), "", this);
	m_volumeButton->setCheckable(true);
	m_layout->addWidget(m_volumeButton);
	connect(m_volumeButton, SIGNAL(toggled(bool)), this, SLOT(slotVolumeButtonToggled(bool)));
	
}

void PlayerController::addActions(QAction *prev, QAction *playPause, QAction *next, QAction *stop){
	m_actionPrev = prev;
	m_buttonPrev->setText(prev->text());
	m_buttonPrev->setIcon(prev->icon());
	connect(m_buttonPrev, SIGNAL(clicked()), m_actionPrev, SLOT(trigger()));
	
	m_actionPlayPause = playPause;
	m_buttonPlayPause->setText(playPause->text());
	m_buttonPlayPause->setIcon(playPause->icon());
	connect(m_buttonPlayPause, SIGNAL(clicked()), m_actionPlayPause, SLOT(trigger()));
	connect(m_actionPlayPause, SIGNAL(changed()), this, SLOT(slotActionPlayPauseChanged()));
	
	m_actionNext = next;
	m_buttonNext->setText(next->text());
	m_buttonNext->setIcon(next->icon());
	connect(m_buttonNext, SIGNAL(clicked()), m_actionNext, SLOT(trigger()));
	
	m_actionStop = stop;
	m_buttonStop->setText(stop->text());
	m_buttonStop->setIcon(stop->icon());
	connect(m_buttonStop, SIGNAL(clicked()), m_actionStop, SLOT(trigger()));
	connect(m_actionStop, SIGNAL(changed()), this, SLOT(slotActionStopChanged()));
}

void PlayerController::slotActionPlayPauseChanged(){
	m_buttonPlayPause->setText(m_actionPlayPause->text());
	m_buttonPlayPause->setIcon(m_actionPlayPause->icon());
}

void PlayerController::slotActionStopChanged(){
	m_buttonStop->setEnabled(m_actionStop->isEnabled());
}

PlayerController::~PlayerController(){
	m_player = 0;//Deleted by MainWindow
//	m_volumeSlider = 0;//Deleted by m_volumeDock
	//m_volumeDock = 0;//Deleted by MainWindow
	//Deleted by MainWindow
	m_actionNext = 0;
	m_actionPlayPause = 0;
	m_actionPrev = 0;
	m_actionStop = 0;
}

void PlayerController::slotVolumeButtonToggled(bool toggled){
	if(toggled){
	//	m_volumeDock->show();
//		m_volumeSlider->show();
	}else{
		//m_volumeDock->hide();
		//m_volumeSlider->hide();
	}
}
